package ioc

import (
	"gitee.com/xiao_hange/go-admin-pkg/pkg/logger"
	"github.com/olivere/elastic/v7"
	"github.com/spf13/viper"
	"go-admin/server/internal/service/search"
	"go-admin/server/internal/service/search/es"
)

func InitEs(l logger.AppLogger) search.Service {
	type config struct {
		Addr []string `yaml:"addr"`
	}
	var cfg config
	err := viper.UnmarshalKey("es", &cfg)
	client, err := elastic.NewClient(
		elastic.SetURL(cfg.Addr...),
		elastic.SetSniff(false),
	)
	if err != nil {
		panic(err)
	}

	return es.NewService(client, l)
}
